package com.ufgov.agcfs.taskPreset.web;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ufgov.agcfs.taskPreset.entity.IpComp;
import com.ufgov.agcfs.taskPreset.service.AllQueryService;
import com.ufgov.agcfs.taskPreset.service.IpCompAllInfoService;
import com.ufgov.agcfs.taskPreset.service.NdService;
import com.ufgov.agcfs.taskPreset.service.OutPutExcelService;

@Controller
@RequestMapping(value="/data_status")
public class AllQueryController {
	@Autowired
	private AllQueryService allQueryService;
	@Autowired
	private IpCompAllInfoService ipCompAllInfoService;
	@Autowired
	private NdService ndService;
	@Autowired
	private OutPutExcelService outPutExcelService;
	//只是返回年度信息
	@RequestMapping(value="/ndInfo",method=RequestMethod.GET)
	public @ResponseBody Map<String,Object> queryNdInfo(HttpServletRequest request,HttpServletResponse response){
		Map<String, Object> result=new HashMap<String, Object>();
		List<String> data=ndService.selectNd();
		if(data!=null){
			result.put("data", data);
			result.put("msg", "success");
		}else{
			result.put("msg", "fail");
		}
		return result;
	}
	
	//返回单位名称,整个实体的信息一起返回
	@RequestMapping(value="/coNameInfo",method=RequestMethod.GET)
	public @ResponseBody Map<String, Object> queryCoNameInfo(HttpServletRequest request,HttpServletResponse response){
		Map<String, Object> result=new HashMap<String, Object>();
		List<IpComp> data=ipCompAllInfoService.selectAllInfo();
		if(data!=null){
			result.put("data", data);
			result.put("msg", "success");
		}else{
			result.put("msg", "fail");
		}
		return result;
	}
	
	//通过传入的单位代码，年度，上级代码，返回列表信息
	@RequestMapping(value="/allRowInfo",method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> queryAllRowInfo(HttpServletRequest request,HttpServletResponse response){
		
		String nd=request.getParameter("nd");  //获取请求参数nd
		String co_code=request.getParameter("co_code"); //获取请求参数 co_code
		String parent_co_id=request.getParameter("parent_co_id"); //获取请求参数 parent_co_id
		
		Map<String, Object> result=new HashMap<String, Object>();
		List<String> data=allQueryService.queryInfoByDwList(nd, co_code, parent_co_id);
		if(data!=null){
			result.put("data", data);
			result.put("msg", "success");
		}else{
			result.put("msg", "fail");
		}
		return result;
	}
	//导出excel
	@RequestMapping(value="/outPutExcel",method=RequestMethod.POST)
	public @ResponseBody Boolean outPutExcel(HttpServletRequest request,HttpServletResponse response) throws IOException{
		String nd=request.getParameter("nd");
		String co_code=request.getParameter("co_code");
		String parent_co_id=request.getParameter("parent_co_id");
		if(outPutExcelService.outPutExcel(nd, co_code, parent_co_id)){
			return true;
		}
		return false;
	}
}
